/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao.erp;

import com.openbravo.data.loader.query.QBFParameters;
import e.odbo.data.dao.ViewDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.sqlbuilder.QBFBuilder;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;
import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.bean.erp.viewbean.ERPAnalysisInfo;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class ERPAnalysisInfoDAO extends ViewDAO<ERPAnalysisInfo>{

    public ERPAnalysisInfoDAO(I_Session s) {
        super(s);
    }

    @Override
    public Class getSuportClass() {
        return ERPAnalysisInfo.class;
    }

    public ERPAnalysisInfo readValues(DataRead dr,ERPAnalysisInfo p) throws BasicException {
        if(p==null)
        	p=new ERPAnalysisInfo();
        p.orderTypeName=dr.getString(1);
        p.orderType=dr.getInt(2);
        p.curDate=dr.getTimestamp(3);
        p.localName=dr.getString(4);
        p.userName=dr.getString(5);
        p.customerName=dr.getString(6);
        p.productName=dr.getString(7);
        p.prodCategoresName=dr.getString(8);
        p.unit=dr.getDouble(9);
        p.totalPrice=dr.getDouble(10);
        return p;
    }

    public List<ERPAnalysisInfo> list(Object filter) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT  E.NAME, T.ORDERTYPE, T.CURDATE, S.NAME, P.NAME, C.NAME, PS.NAME, CS.NAME, L.UNITS, L.UNITS*L.PRICE  "
                + "FROM ORDERLINES L LEFT  JOIN ORDERS T ON L.ORDERRID = T.ID "
                + "LEFT OUTER JOIN CUSTOMERS C ON  T.CUSTOMER=C.ID "
                + "LEFT OUTER JOIN LOCATIONS S ON T.LOCATIONREF=S.ID "
                + "LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID "
                + "LEFT OUTER JOIN ORDERTYPES E ON T.DEFINETYPEREF = E.ID "
                + "LEFT OUTER JOIN PRODUCTS PS ON L.PRODUCT = PS.ID "
                + "LEFT OUTER JOIN CATEGORIES CS ON PS.CATEGORY = CS.ID "
                + "WHERE ?(QBF_FILTER)  ORDER BY T.CURDATE DESC ", new String[]{"T.DEFINETYPEREF", "T.CURDATE", "T.CURDATE", "T.LOCATIONREF", "T.PERSON", "T.CUSTOMER", "L.PRODUCT", "PS.CATEGORY"}), new SerializerWriteBasic(new Datas[]{Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.OBJECTS, Datas.OBJECT, Datas.OBJECTS}), this).list(filter);
    }

    @Override
    public List<ERPAnalysisInfo> query(QBFParameters qbfParameters) throws BasicException {
        return new StaticSentence(s, new QBFBuilder(
                "SELECT  E.NAME, T.ORDERTYPE, T.CURDATE, S.NAME, P.NAME, C.NAME, PS.NAME, CS.NAME, L.UNITS, L.UNITS*L.PRICE  "
                        + "FROM ORDERLINES L LEFT  JOIN ORDERS T ON L.ORDERRID = T.ID "
                        + "LEFT OUTER JOIN CUSTOMERS C ON  T.CUSTOMER=C.ID "
                        + "LEFT OUTER JOIN LOCATIONS S ON T.LOCATIONREF=S.ID "
                        + "LEFT OUTER JOIN PEOPLE P ON T.PERSON = P.ID "
                        + "LEFT OUTER JOIN ORDERTYPES E ON T.DEFINETYPEREF = E.ID "
                        + "LEFT OUTER JOIN PRODUCTS PS ON L.PRODUCT = PS.ID "
                        + "LEFT OUTER JOIN CATEGORIES CS ON PS.CATEGORY = CS.ID "
                        + "WHERE ?(QBF_FILTER)  ORDER BY T.CURDATE DESC "),null, this).list(qbfParameters);
    }
}

